package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsComment;
import com.qf.service.DtsCommentService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/24 9:22
 */
@RequestMapping("/admin/comment")
@RestController
@CrossOrigin
public class AdminCommentController {

    @Autowired
    private DtsCommentService commentService;

    /**
     * http://localhost:8083/admin/comment/list?page=1&limit=20&sort=add_time&order=desc
     * @param userId
     * @param valueId
     * @param order
     * @param sort
     * @param page
     * @param limit
     * @return
     */
    @RequiresPermissions(value = "admin:comment:list")
    @RequiresPermissionsDesc(menu = {"商品管理","商品评论"},button = "查询")
    @GetMapping("/list")
    public Object list(String userId, String valueId,
                       String order,
                       String sort,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "20") Integer limit){
        //分页对象
        IPage<DtsComment> iPage = commentService.findListByQuery(userId,valueId,sort,order,page,limit);
        Map data = new HashMap<>();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return ResponseUtil.ok(data);
    }

    /**
     * delete
     * @return
     */
    @RequiresPermissions(value = "admin:comment:delete")
    @RequiresPermissionsDesc(menu = {"商品管理","商品评论"},button = "删除")
    @PostMapping("/delete")
    public Object delete(@RequestBody DtsComment dtsComment){
        dtsComment = commentService.delete(dtsComment);
        return dtsComment;
    }

}
